#!/bin/bash

# env prepare
sudo apt-get install gcc-mingw-w64

# configure
MINGW_PREFIX=$(pwd)/mingw64
MINGW_PREBUILTS_CLANG=
MINGW_CHOST=x86_64-w64-mingw32
MINGW_BUILD=x86_64-unknown-linux-gnu
TOOLCHAIN_ROOT=${MINGW_PREBUILTS_CLANG}/linux-x86_64/clang-mingw/bin
SYSROOT=${MINGW_PREBUILTS_CLANG}/linux-x86_64/clang-mingw/x86_64-w64-mingw32

export CC=$TOOLCHAIN_ROOT/clang
export CXX=$TOOLCHAIN_ROOT/clang++


export CFLAGS="-target ${MINGW_CHOST} --sysroot=$SYSROOT"
export LDFLAGS="--sysroot=$SYSROOT -rtlib=compiler-rt -target ${MINGW_CHOST} -lucrt -lucrtbase -fuse-ld=lld"

./configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --build=${MINGW_BUILD} \
    --enable-shared \
    --enable-static \
    --without-ensurepip \
    --without-c-locale-coercion \
    --enable-loadable-sqlite-extensions
